package com.crm.CLdriving.service.impl;


import cn.hutool.crypto.SecureUtil;
import com.crm.CLdriving.common.BaseResponse;
import com.crm.CLdriving.enu.ResponseEnum;
import com.crm.CLdriving.exception.MyServiceException;
import com.crm.CLdriving.mapper.UserMapper;
import com.crm.CLdriving.po.UserPO;
import com.crm.CLdriving.service.UserService;
import com.crm.CLdriving.util.token.TokenUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;


@Service
@Log4j2
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    /**
     * 通过账户查找用户
     * @param name
     * @return
     */
    @Override
    public UserPO getUserByName(String name){
        if(!userMapper.findByName(name).getName().isEmpty()){
            return userMapper.findByName(name);
        } else {
            throw new MyServiceException(ResponseEnum.ZWSJ);
        }
    }

    /**
     * 根据token获取当前用户
     * @return
     */
    @Override
    public UserPO getCurUser(){
        return TokenUtils.getCurUser();
    }


}
